/** @file store.h
 *
 * @brief Generic store dependency.
 *
 * This code allows to use the store interface with any supported back end
 * without any knowledge of the back end implementations. Code using the store
 * interface need only include this file.
 *
 * New store implementations should be added to this file as `#include`s as
 * well as entries in the `BACKEND_TBL` macro.
 */

#ifndef _LSUP_STORE_H
#define _LSUP_STORE_H

/*
 * Add new back end headers here.
 */
#include "store_htable.h"
#include "store_mdb.h"


/*
 * Define backend types.
 *
 * Add new store implementations to this table.
 */
#define BACKEND_TBL                                                           \
/*          #enum pfx   #store if       */\
    ENTRY(  HTABLE,     htstore_int  )  \
    ENTRY(  MDB,        mdbstore_int ) \


/** @brief Store types. All prefixed with `LSUP_STORE_`.
 */
typedef enum {
#define ENTRY(a, b) \
    LSUP_STORE_##a,
BACKEND_TBL
#undef ENTRY
} LSUP_StoreType;


/** @brief Return store interface for a specific type.
 */
const LSUP_StoreInt *LSUP_store_int (LSUP_StoreType type);


/** @brief Store structure.
 *
 * Code using the store interface should create an instance of this structure
 * with pointers to the store interface of their choice, and to an opaque
 * structure to hold the store state.
 *
 * Iterator state handles generated by lookup and add functions are kept
 * outside of this structure, but manipulated by the interface specified in
 * here.
 *
 * @sa #LSUP_graph_new()
 */
typedef struct store_t {
    LSUP_StoreType                  type;   ///< Store type.
    char *                          id;     /**< Store ID.
                                             *
                                             *   NOTE: This is
                                             *   NULL for volatile stores.
                                             */
    const LSUP_StoreInt *           sif;    ///< Store interface.
    void *                          data;   ///< Store back end data.
} LSUP_Store;

#endif  /* LSUP_STORE_H */
